//电源电池
var PagePower = {
    id: "PagePower", //页面id
    menu: "i18n.lan.menu.basic", //所属菜单(一级菜单名)
    title: "i18n.lan.menu.PagePower", //标题（二级菜单名）
    icon: "icon-me-battery", //图标
    refreshBtnCmd: "IOS_DUMPS", //刷新按钮指令
    saveBtn: true, //保存按钮
    el: [ //控件        
        //dumpParamIndex:"刷新数据可能有多个，这个是指示参数位置序号的"
        { //css定义
            elname: "style",
            text: "#PagePower > label{width:140px;}",
        },
        {
            elname: "checkbox",
            label: i18n.lan.common.smsAlarm,
            id: "power_smsAlarm",
            endRow: true,
            attrs: {
                dumpKey: "POWERNODE_PARAM",
                dumpParamIndex: 0,
                cmdKey: "POWERSMSEN",
            },
        },
        {
            elname: "checkbox",
            label: i18n.lan.common.soundAlarm,
            id: "power_soundAlarm",
            endRow: true,
            attrs: {
                dumpKey: "POWERNODE_PARAM",
                dumpParamIndex: 1,
                cmdKey: "POWERSOUNDEN"
            },
        },
        {
            elname: "text",
            label: i18n.lan.common.ensureTime,
            endRow: true,
            attrs: {
                dumpKey: "POWERNODE_AETO",
                cmdKey: "POWERAETO"
            },
        },
        {
            elname: "text",
            label: i18n.lan.common.stopAlarmTime,
            endRow: true,
            attrs: {
                dumpKey: "POWERNODE_SMSTO",
                dumpParamIndex: "0",
                cmdKey: "POWERASSTO"
            },
        },
        {
            elname: "text",
            label: i18n.lan.common.alarmSmsResendTime,
            endRow: true,
            attrs: {
                dumpKey: "POWERNODE_SMSTO",
                dumpParamIndex: "1",
                cmdKey: "POWERASRTO"
            },
        },
        {
            elname: "text",
            label: i18n.lan.PagePower.powerOffSms,
            endRow: true,
            attrs: {
                transcode: true,
                dumpKey: "POWERMSG",
                dumpParamIndex: 0,
                cmdKey: "POWERMSG",
                getValue: "PagePower_getPowerMsgCmd()",
                id: "PagePower_offsms",
                style: "width:260px",
            },
        },
        {
            elname: "text",
            label: i18n.lan.PagePower.powerOnSms,
            endRow: true,
            attrs: {
                id: "PagePower_onsms",
                transcode: true,
                dumpKey: "POWERMSG",
                dumpParamIndex: 1,
                title: "POWERMSG<>,<?>",
                style: "width:260px",
            },
        },
    ],
}
CmdPage.add(PagePower); //添加到页面管理

//获得设置断电或恢复的短信指令
function PagePower_getPowerMsgCmd() {
    let offsmsIndex = 0;
    let onsmsIndex = 0;
    let offsms, onsms;
    //页面打开了
    if (defined($("#PagePower_offsms").val())) { 
        offsms = $("#PagePower_offsms").val();
        onsms = $("#PagePower_onsms").val();
    } 
    else {
        //找到序号
        for (let i=0;i<PagePower.el.length;i++) {
            if(PagePower.el[i].attrs){
                if (PagePower.el[i].attrs.id == "PagePower_offsms") offsmsIndex = i;
                if (PagePower.el[i].attrs.id == "PagePower_onsms") onsmsIndex = i;
            }
        }
        offsms = PagePower.el[offsmsIndex].attrs.cmdVal;
        onsms = PagePower.el[onsmsIndex].attrs.cmdVal;
    }
    offsms = Device.transCode(offsms);
    onsms = Device.transCode(onsms);
    
    return offsms + "," + onsms;
}